package com.codechuan.hallo_internal.ui.home;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.codechuan.hallo_internal.R;
import com.codechuan.hallo_internal.common.Constant;
import com.codechuan.hallo_internal.databinding.FragmentHomeBinding;
import com.codechuan.hallo_internal.entity.CityInfo;
import com.codechuan.hallo_internal.entity.SysUserAccountNz;
import com.codechuan.hallo_internal.entity.SysUserConfigNz;
import com.codechuan.hallo_internal.utils.ContextUtil;
import com.codechuan.hallo_internal.utils.DataCheckUtil;
import com.codechuan.hallo_internal.utils.DateUtil;
import com.codechuan.hallo_internal.utils.DialogUtil;
import com.codechuan.hallo_internal.utils.HalloProjectHttpUtil;
import com.codechuan.hallo_internal.utils.JDBCRequestUtils;
import com.codechuan.hallo_internal.utils.JDBCUtil;
import com.codechuan.hallo_internal.utils.MyProjectHttpUtil;
import com.example.libbaiduselectlocation.SelectLocationBDActivity;
import com.example.libbaiduselectlocation.bean.SelectLocationBDBean;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class HomeFragment extends Fragment implements View.OnClickListener {

    private FragmentHomeBinding binding;
    private Context context;
    private SimpleDateFormat simpleDateFormat;
    public static TextView startAddressTextVivew;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        if (simpleDateFormat == null)
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        context = getContext();
        binding = FragmentHomeBinding.inflate(inflater, container, false);
        Button saveConfig = binding.saveConfig;
        Constant.button = saveConfig;
        saveConfig.setOnClickListener(this);
        // 日期弹出框和设置宽度
        Button select_time = binding.selecStartTime;
        select_time.setOnClickListener(view2 -> {
            if (context == null) {
                return;
            }
            DatePickerDialog datePickerDialog = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                    SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
                    String time = format.format(new Date());
                    String moon = "";
                    String day = "";
                    i1 = i1 + 1;
                    if (String.valueOf(i1).length() == 1) {
                        moon = "0" + i1;
                    } else {
                        moon = moon + i1;
                    }
                    if (String.valueOf(i2).length() == 1) {
                        day = "0" + i2;
                    } else {
                        day = day + i2;
                    }
                    binding.startTime.setText(i + "-" + moon + "-" + day + " " + time + ":00");
                }
            }, 2024, 10, 26);
            datePickerDialog.show();
        });

        // 日期弹出框和设置宽度
        Button selecEndTime = binding.selecEndTime;
        selecEndTime.setOnClickListener(view2 -> {
            if (context == null) {
                return;
            }
            DatePickerDialog datePickerDialog = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                    SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
                    String time = format.format(new Date());
                    String moon = "";
                    String day = "";
                    i1 = i1 + 1;
                    if (String.valueOf(i1).length() == 1) {
                        moon = "0" + i1;
                    } else {
                        moon = moon + i1;
                    }
                    if (String.valueOf(i2).length() == 1) {
                        day = "0" + i2;
                    } else {
                        day = day + i2;
                    }
                    binding.endTime.setText(i + "-" + moon + "-" + day + " " + time + ":00");
                }
            }, 2024, 10, 26);
            datePickerDialog.show();
        });
        // 虚拟定位按钮
        binding.position.setOnClickListener(this);
        // 实时定位按钮
        binding.ssdwButton.setOnClickListener(this);
        // 赋值位置给ui
        startAddressTextVivew = binding.startAddressText;
        return binding.getRoot();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    // 是否发送验证码
    public static boolean isSendCode = false;

    /**
     * @Deprecated 页面进入数据初始化
     */
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        // 判断用户是否需要提取token
        if (Constant.account == null || Constant.account == "") {
            Constant.handler.post(() -> {
                DialogUtil.showDialog(ContextUtil.context, "未获取到手机号,请退出软件重新打开!");
            });
            return;
        }
        Constant.executorService.execute(new Runnable() {
            @Override
            public void run() {
               SysUserAccountNz sysUserAccountNz =  MyProjectHttpUtil.getUserAccount();
                if (sysUserAccountNz.getToken() == null || sysUserAccountNz.getTokenStatus().equals("1")) {
                    if (sysUserAccountNz.getToken() == null) {
                        Constant.handler.post(() -> {
                            DialogUtil.showDialog(ContextUtil.context, "新用户请绑定主号~,老用户请重新打开APP");
                        });
                    } else {
                        if (sysUserAccountNz.getTokenStatus().equals("1")) {
                            Constant.handler.post(() -> {
                                DialogUtil.showDialog(ContextUtil.context, "主号登录已过期~请重新绑定主号");
                            });
                        }
                    }
                    Constant.handler.post(()->{

                        View inflate = LayoutInflater.from(getContext()).inflate(R.layout.add_main_token, null);
                        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                        AlertDialog alertDialog = builder.create();
                        alertDialog.setView(inflate);
                        alertDialog.show();
                        Window window = alertDialog.getWindow();
                        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                        lp.copyFrom(alertDialog.getWindow().getAttributes());
                        lp.width = Constant.dm.widthPixels * 4 / 5 + 150;
                        window.setAttributes(lp);
                        // 获取发验证码事件
                        Button send_code = inflate.findViewById(R.id.send_code);
                        send_code.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Constant.executorService.execute(new Runnable() {
                                    @Override
                                    public void run() {
                                        String weChatMiniProgramCode = HalloProjectHttpUtil.getWeChatMiniProgramCode(Constant.account);
                                        Constant.handler.post(() -> {
                                            DialogUtil.showDialog(ContextUtil.context, weChatMiniProgramCode);
                                        });
                                        isSendCode = true;
                                    }
                                });
                            }
                        });
                        // 获取添加按钮事件
                        Button submit_add = inflate.findViewById(R.id.submit_add);
                        submit_add.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                System.out.println("添加小号");
                                if (!isSendCode) {
                                    Constant.handler.post(() -> {
                                        DialogUtil.showDialog(ContextUtil.context, "请先发送验证码!");
                                    });
                                } else {
                                    // 获取组件上的验证码
                                    TextView codeView = inflate.findViewById(R.id.code);
                                    String code = codeView.getText().toString();
                                    if (code == null || code.replaceAll(" ", "").equals("")) {
                                        Constant.handler.post(() -> {
                                            DialogUtil.showDialog(ContextUtil.context, "请输入正确的验证码!");
                                        });
                                        return;
                                    }
                                    // 执行登录获取token
                                    Constant.executorService.execute(new Runnable() {
                                        @Override
                                        public void run() {
                                            JSONObject jsonObject = HalloProjectHttpUtil.getWeChatMiniProgramToken(Constant.account, code.replaceAll(" ", ""));
                                            if (jsonObject == null) {
                                                Constant.handler.post(() -> {
                                                    DialogUtil.showDialog(ContextUtil.context, "验证码失效,或验证码不正确!");
                                                });
                                                return;
                                            }
                                            String token = jsonObject.getString("token");
                                            String ticket = jsonObject.getString("ticket");
                                            // 修改账号实体类
                                            boolean falg = MyProjectHttpUtil.updateAccountToken(Constant.account, token, ticket);
                                            if (falg) {
                                                // 设置常量信息
                                                Constant.handler.post(() -> {
                                                    Constant.ticket = ticket;
                                                    Constant.token = token;
                                                    DialogUtil.showDialog(ContextUtil.context, "绑定成功!");
                                                    alertDialog.dismiss();
                                                });
                                            } else {
                                                Constant.handler.post(() -> {
                                                    DialogUtil.showDialog(ContextUtil.context, "绑定失败!");
                                                });
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        // 获取取消按钮事件
                        Button submit_qx = inflate.findViewById(R.id.submit_qx);
                        submit_qx.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                alertDialog.dismiss();
                            }
                        });

                    });
                } else {
                    // 设置 token和ticket
                    Constant.token = sysUserAccountNz.getToken();
                    Constant.ticket = sysUserAccountNz.getTicket();
                }
            }
        });

        // 读取配置
        // 接单模型
        RadioButton CJ_ORDER_CHECK = view.findViewById(R.id.cj);
        if (CJ_ORDER_CHECK != null) CJ_ORDER_CHECK.setChecked(Constant.CJ_ORDER);
        RadioButton SN_ORDER_CHECK = view.findViewById(R.id.sn);
        if (SN_ORDER_CHECK != null) SN_ORDER_CHECK.setChecked(Constant.SN_ORDER);

        // 接口模式
        RadioButton APP_IS_CHECK = view.findViewById(R.id.appController);
        if (APP_IS_CHECK != null) APP_IS_CHECK.setChecked(Constant.APP_IS_CHECK);
        RadioButton XCX_IS_CHECK = view.findViewById(R.id.xcxController);
        if (XCX_IS_CHECK != null) XCX_IS_CHECK.setChecked(Constant.XCX_IS_CHECK);

        // 虚拟定位地址
        TextView START_ADDRESS = view.findViewById(R.id.startAddressText);
        if (START_ADDRESS != null) START_ADDRESS.setText(Constant.startAddress);


        // 最小金额和最大金额
        TextView MIN_MONEY = view.findViewById(R.id.miniMoney);
        if (MIN_MONEY != null) MIN_MONEY.setText(String.valueOf(Constant.MIN_MONEY));
        TextView MAX_MONEY = view.findViewById(R.id.maxMoney);
        if (MAX_MONEY != null) MAX_MONEY.setText(String.valueOf(Constant.MAX_MONEY));

        // 开始时间和结束时间
        Constant.START_TIME_STRING = Constant.START_TIME_STRING;
        if (Constant.START_TIME_STRING == null || Constant.START_TIME_STRING.isEmpty()) {
            Constant.START_TIME_STRING = simpleDateFormat.format(new Date());
        }
        Constant.END_TIME_STRING = Constant.END_TIME_STRING;
        if (Constant.END_TIME_STRING == null || Constant.END_TIME_STRING.isEmpty()) {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            Constant.END_TIME_STRING = simpleDateFormat.format(calendar.getTime());
        }
        TextView START_TIME = view.findViewById(R.id.startTime);
        if (START_TIME != null) START_TIME.setText(Constant.START_TIME_STRING);
        TextView END_TIME = view.findViewById(R.id.endTime);
        if (END_TIME != null) END_TIME.setText(Constant.END_TIME_STRING);

        // 接单模型
        Switch ZJ_DX = view.findViewById(R.id.zjdxd);
        if (ZJ_DX != null) ZJ_DX.setChecked(Constant.ZJ_DX);
        Switch YD_GS = view.findViewById(R.id.ydgsf);
        if (YD_GS != null) YD_GS.setChecked(Constant.YD_GS);
        Switch QD_DW = view.findViewById(R.id.dwsy);
        if (QD_DW != null) QD_DW.setChecked(Constant.QD_DW);

        CheckBox LX_QD = view.findViewById(R.id.lxqd);
        if (LX_QD != null) LX_QD.setChecked(Constant.LX_QD);

        // 起点和终点
        TextView MAX_STARTING_POINT_DISTANCE = view.findViewById(R.id.miniDes);
        if (MAX_STARTING_POINT_DISTANCE != null)
            MAX_STARTING_POINT_DISTANCE.setText(String.valueOf(Constant.DT_START_DES));

        TextView MAX_END_POINT_DISTANCE = view.findViewById(R.id.maxDes);
        if (MAX_END_POINT_DISTANCE != null)
            MAX_END_POINT_DISTANCE.setText(String.valueOf(Constant.DT_END_DES));

        // 刷脸模式
        RadioButton APP = view.findViewById(R.id.appController);
        if (APP != null) APP.setChecked(Constant.APP_IS_CHECK);

        RadioButton XCX = view.findViewById(R.id.xcxController);
        if (XCX != null) XCX.setChecked(Constant.XCX_IS_CHECK);


        // 订单排序规则
        RadioButton ZN_PX = view.findViewById(R.id.znpx);
        if (ZN_PX != null) ZN_PX.setChecked(Constant.ZN_PX_CHECK);

        RadioButton ZZ_CHECK = view.findViewById(R.id.sjpx);
        if (ZZ_CHECK != null) ZZ_CHECK.setChecked(Constant.ZZ_CHECK);

        RadioButton ZJ_CHECK = view.findViewById(R.id.jlpx);
        if (ZJ_CHECK != null) ZJ_CHECK.setChecked(Constant.ZJ_CHECK);

        RadioButton ZG_CHECK = view.findViewById(R.id.jgpx);
        if (ZG_CHECK != null) ZG_CHECK.setChecked(Constant.ZG_CHECK);

        TextView xld = view.findViewById(R.id.xld);
        xld.setText(String.valueOf(Constant.XC_SLD));

        // 接单类型
        CheckBox DX_IS_CHECK = view.findViewById(R.id.dxgzCheckBox);
        if (DX_IS_CHECK != null) DX_IS_CHECK.setChecked(Constant.DX_PERSON_CHECKBOX);
        TextView DX_MIN_NUMBER = view.findViewById(R.id.dxMinPerson);
        if (DX_MIN_NUMBER != null) DX_MIN_NUMBER.setText(String.valueOf(Constant.DX_MIN_NUMBER));
        TextView DX_MAX_NUMBER = view.findViewById(R.id.dxMaxPerson);
        if (DX_MAX_NUMBER != null) DX_MAX_NUMBER.setText(String.valueOf(Constant.DX_MAX_NUMBER));

        CheckBox PC_IS_CHECK = view.findViewById(R.id.pcgzCheckBox);
        if (PC_IS_CHECK != null) PC_IS_CHECK.setChecked(Constant.PC_PERSON_CHECKBOX);
        TextView PC_MIN_NUMBER = view.findViewById(R.id.pcMinPerson);
        if (PC_MIN_NUMBER != null) PC_MIN_NUMBER.setText(String.valueOf(Constant.PC_MIN_NUMBER));
        TextView PC_MAX_NUMBER = view.findViewById(R.id.pcMaxPerson);
        if (PC_MAX_NUMBER != null) PC_MAX_NUMBER.setText(String.valueOf(Constant.PC_MAX_NUMBER));

        CheckBox SS_IS_CHECK = view.findViewById(R.id.ssgzCheckBox);
        if (SS_IS_CHECK != null) SS_IS_CHECK.setChecked(Constant.SS_PERSON_CHECKBOX);
        TextView SS_MIN_NUMBER = view.findViewById(R.id.ssMinPerson);
        if (SS_MIN_NUMBER != null) SS_MIN_NUMBER.setText(String.valueOf(Constant.SS_MIN_NUMBER));
        TextView SS_MAX_NUMBER = view.findViewById(R.id.ssMaxPerson);
        if (SS_MAX_NUMBER != null) SS_MAX_NUMBER.setText(String.valueOf(Constant.SS_MAX_NUMBER));


        CheckBox PC_TH_CHECK = view.findViewById(R.id.pcth);
        if (PC_TH_CHECK != null) PC_TH_CHECK.setChecked(Constant.PC_TH_CHECK);

        // 指定城市和排除城市
        CheckBox ZD_CS_CHECK = view.findViewById(R.id.zdcs_check);
        if (ZD_CS_CHECK != null) ZD_CS_CHECK.setChecked(Constant.ZD_CS_CHECK);
        TextView ZD_CS_TEXT = view.findViewById(R.id.zdcs);
        if (ZD_CS_TEXT != null) ZD_CS_TEXT.setText(String.valueOf(Constant.ZD_CS_TEXT));

        CheckBox PC_CS_CHECK = view.findViewById(R.id.pccs_check);
        if (PC_CS_CHECK != null) PC_CS_CHECK.setChecked(Constant.ZD_CS_CHECK);
        TextView PC_CS_TEXT = view.findViewById(R.id.zdcs);
        if (ZD_CS_TEXT != null) ZD_CS_TEXT.setText(String.valueOf(Constant.ZD_CS_TEXT));


    }

    // 在Activity中调用此方法
    private void openWebPage(String url) {
        if (url != null && !url.trim().isEmpty()) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
        }
    }

    @Override
    public void onClick(View view) {
        // 虚拟定位按钮
        if (view.getId() == R.id.position) {
            FragmentActivity activity = getActivity();
            if (activity != null) {
                SelectLocationBDActivity.Companion.startActivityForResult(activity, 99);
            }
        }
        // 实时定位按钮
        if (view.getId() == R.id.ssdw_button) {
            binding.startAddressText.setText(Constant.SS_DW_ADDRESS);
            // 判断是否实时定位失败
            if (Constant.SS_DW_ADDRESS.contains("请手动定位~")) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "请手动定位~");
                });
                return;
            }
            // 开始定位
            Constant.executorService.execute(new Runnable() {
                @Override
                public void run() {
                    CityInfo cityInfo = null;
                    try {
                        cityInfo = MyProjectHttpUtil.getCityInfo(Constant.SS_DW_ADDRESS);
                    } catch (Exception e) {
                        Constant.handler.post(() -> {
                            DialogUtil.showDialog(ContextUtil.context, "定位失败~");
                        });
                    }
                    if (cityInfo == null) {
                        Constant.handler.post(() -> {
                            DialogUtil.showDialog(ContextUtil.context, "定位失败~");
                        });
                        return;
                    }
                    Constant.cityInfo = cityInfo;
                    if (cityInfo != null) {
                        Constant.handler.post(() -> {
                            DialogUtil.showDialog(ContextUtil.context, "定位成功~");
                        });
                    }
                }
            });
        }
        // 保存配置按钮
        if (view.getId() == R.id.save_config) {
            if (!Constant.is_zx) {
                try {
                    Constant.handler.post(() -> {
                        DialogUtil.showDialog(ContextUtil.context, "当前版本不是最新,请及时更新!");

                    });
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "即将为你打开下载网址!");

                });
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                Constant.handler.post(() -> {
                    openWebPage("http://45.251.9.55:9999");

                });
                return;
            }
            // 判断是否定位
            if (Constant.cityInfo == null) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "请先定位,精准到省市区哦~");
                });
                return;
            }
            // 获取刷单模式
            if (binding.cj.isChecked()) {
                Constant.CJ_ORDER = true;
                Constant.requestType = "3";
                Constant.requestTypeParam = "requestType3Param";
            } else {
                Constant.CJ_ORDER = false;
            }

            if (binding.sn.isChecked()) {
                Constant.SN_ORDER = true;
                Constant.requestType = "2";
                Constant.requestTypeParam = "requestType2Param";
            } else {
                Constant.SN_ORDER = false;
            }

            // 获取排序规则
            Constant.ZN_PX_CHECK = binding.znpx.isChecked();
            Constant.ZZ_CHECK = binding.sjpx.isChecked();
            Constant.ZJ_CHECK = binding.jlpx.isChecked();
            Constant.ZG_CHECK = binding.jgpx.isChecked();
            if (Constant.ZN_PX_CHECK)
                Constant.SORT = 1;
            if (Constant.ZZ_CHECK)
                Constant.SORT = 2;
            if (Constant.ZJ_CHECK)
                Constant.SORT = 3;
            if (Constant.ZG_CHECK)
                Constant.SORT = 4;

            // 刷脸规则
            Constant.APP_IS_CHECK = binding.appController.isChecked();
            Constant.XCX_IS_CHECK = binding.xcxController.isChecked();

            Constant.ZJ_DX = binding.zjdxd.isChecked();
            Constant.YD_GS = binding.ydgsf.isChecked();

            // 获取位置
            //Constant.startAddress = binding.startAddressText.getText().toString();


            // 价格规则
            Constant.MIN_MONEY = Integer.parseInt(binding.miniMoney.getText().toString());
            Constant.MAX_MONEY = Integer.parseInt(binding.maxMoney.getText().toString());

            // 距离规则

            Constant.DT_START_DES = Integer.parseInt(binding.miniDes.getText().toString());
            Constant.DT_END_DES = Integer.parseInt(binding.maxDes.getText().toString());
            Constant.XC_END_DES = Integer.parseInt(binding.zdjl.getText().toString());
            // 顺路单规则
            Constant.XC_SLD = Integer.parseInt(binding.xld.getText().toString());


            //获取接单规则
            Constant.PC_PERSON_CHECKBOX = binding.pcgzCheckBox.isChecked();
            Constant.PC_MIN_NUMBER = Integer.parseInt(binding.pcMinPerson.getText().toString());
            Constant.PC_MAX_NUMBER = Integer.parseInt(binding.pcMaxPerson.getText().toString());

            Constant.DX_PERSON_CHECKBOX = binding.dxgzCheckBox.isChecked();
            Constant.DX_MIN_NUMBER = Integer.parseInt(binding.dxMinPerson.getText().toString());
            Constant.DX_MAX_NUMBER = Integer.parseInt(binding.dxMaxPerson.getText().toString());

            Constant.SS_PERSON_CHECKBOX = binding.ssgzCheckBox.isChecked();
            Constant.SS_MIN_NUMBER = Integer.parseInt(binding.ssMinPerson.getText().toString());
            Constant.SS_MAX_NUMBER = Integer.parseInt(binding.ssMaxPerson.getText().toString());

            // 排除特惠
            Constant.PC_TH_CHECK = binding.pcth.isChecked();


            // 获取连续抢单规则
            Constant.LX_QD = binding.lxqd.isChecked();

            // 排除城市规则
            Constant.PC_CS_CHECK = binding.pccsCheck.isChecked();
            Constant.PC_CS_TEXT = binding.pccs.getText().toString();

            // 指定城市规则
            Constant.ZD_CS_CHECK = binding.zdcsCheck.isChecked();
            Constant.ZD_CS_TEXT = binding.zdcs.getText().toString();

            // 校验获取刷单模式
            if (Constant.SN_ORDER == false && Constant.CJ_ORDER == false) {
                if (Constant.APP_IS_CHECK) {
                    Constant.handler.post(() -> {
                        DialogUtil.showDialog(ContextUtil.context, "APP目前不支持行程刷新订单~");
                    });
                    return;
                }
            }

            // 排序规则校验
            if (!Constant.ZN_PX_CHECK && !Constant.ZZ_CHECK && !Constant.ZJ_CHECK && !Constant.ZG_CHECK) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "订单排序规则必须选择一项.");
                });
                return;
            }

            // 刷脸规则校验
            if (!Constant.APP_IS_CHECK && !Constant.XCX_IS_CHECK) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "刷脸模式必须选择一项~");
                });
                return;
            }

            // 获取接口模式
            if (Constant.XC_ORDER && Constant.APP_IS_CHECK) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "APP无法刷取行程订单~");
                });
                return;
            }

            // 开始时间/结束时间校验规则
            EditText startTime = binding.startTime;
            EditText endTime = binding.endTime;
            if (startTime.getText().toString() == null || startTime.getText().toString().equals("")) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "开始时间不能为空~");
                });
                return;
            }
            if (endTime.getText().toString() == null || endTime.getText().toString().equals("")) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "结束时间不能为空~");
                });
                return;
            }
            if (!DataCheckUtil.dateCheck(startTime.getText().toString()) || !DataCheckUtil.dateCheck(endTime.getText().toString())) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "开始时间或结束时间设置错误~");
                });
                return;
            }
            Constant.START_TIME_STRING = startTime.getText().toString();
            Constant.START_TIME = DateUtil.passDate(startTime.getText().toString());
            Constant.END_TIME_STRING = endTime.getText().toString();
            Constant.END_TIME = DateUtil.passDate(endTime.getText().toString());

            // 人数规则校验
            if (!Constant.PC_PERSON_CHECKBOX && !Constant.DX_PERSON_CHECKBOX && !Constant.SS_PERSON_CHECKBOX) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "人数规则必须选择一项~");
                });
                return;
            }


            if (Constant.XCX_IS_CHECK) {        // 获取自己发布的行程
                Constant.executorService.execute(new Runnable() {
                    @Override
                    public void run() {
                        JSONObject jsonObject = HalloProjectHttpUtil.getWeChatMiniMyOrderOrMyScheduleOrder();
                        if (jsonObject.getString("code").equals("0")) {
                            // 获取行程数组
                            JSONArray data = jsonObject.getJSONArray("data");
                            if (data.size() <= 0) {
                                Constant.handler.post(() -> {
                                    DialogUtil.showDialog(ContextUtil.context, "请先发布一个行程在使用小程序刷单~");
                                });
                            }
                            for (Object datum : data) {
                                JSONObject dataList = JSONObject.parseObject(datum.toString());
                                JSONArray paxOrderList = dataList.getJSONArray("paxOrderList");
                                if (paxOrderList.size() > 0) {
                                    continue;
                                } else {
                                    Constant.routeId = dataList.getString("driverJourneyGuid");

                                }
                            }
                        }
                    }
                });
            }
            if (Constant.XCX_IS_CHECK && Constant.routeId == null) {
                Constant.handler.post(() -> {
                    DialogUtil.showDialog(ContextUtil.context, "请先发布一个全新的任意行程再保存配置~");
                });
                return;
            }

            // 判断是否设置指定城市
            if (binding.zdcsCheck.isChecked()) {
                // 获取城市信息
                String zdCsText = binding.zdcs.getText().toString();
                Constant.ZD_CS_TEXT = zdCsText;
                Constant.executorService.execute(new Runnable() {
                    @Override
                    public void run() {
                        MyProjectHttpUtil.selectZdCsCityCode(zdCsText);

                    }
                });
            }

            // 保存配置到数据库
            Constant.executorService.execute(new Runnable() {
                @Override
                public void run() {
                    // 先删除配置
                    //JDBCUtil.deleteAccountConfig(Constant.account);
                    SysUserConfigNz sysUserConfigNz = new SysUserConfigNz();
                    if (Constant.SN_ORDER) {
                        sysUserConfigNz.setJdMs("0");
                    }
                    if (Constant.CJ_ORDER) {
                        sysUserConfigNz.setJdMs("1");
                    }
                    if (Constant.XC_ORDER) {
                        sysUserConfigNz.setJdMs("2");
                    }
                    if (Constant.ZN_PX_CHECK) {
                        sysUserConfigNz.setPxGz("1");
                    }
                    if (Constant.ZZ_CHECK) {
                        sysUserConfigNz.setPxGz("2");
                    }
                    if (Constant.ZJ_CHECK) {
                        sysUserConfigNz.setPxGz("3");
                    }
                    if (Constant.ZG_CHECK) {
                        sysUserConfigNz.setPxGz("4");
                    }

                    if (Constant.APP_IS_CHECK) {
                        sysUserConfigNz.setRzMs("1");
                    }
                    if (Constant.XCX_IS_CHECK) {
                        sysUserConfigNz.setRzMs("2");
                    }

                    sysUserConfigNz.setZjDx(Constant.ZJ_DX == true ? "1" : "0");
                    sysUserConfigNz.setYdGs(Constant.YD_GS == true ? "1" : "0");
                    sysUserConfigNz.setQdDw(Constant.QD_DW == true ? "1" : "0");
                    sysUserConfigNz.setPcTh(Constant.PC_TH_CHECK == true ? "1" : "0");

                    sysUserConfigNz.setMiniMoney(String.valueOf(Constant.MIN_MONEY));
                    sysUserConfigNz.setMaxMoney(String.valueOf(Constant.MAX_MONEY));

                    sysUserConfigNz.setDtStartDes(String.valueOf(Constant.DT_START_DES));
                    sysUserConfigNz.setDtEndDes(String.valueOf(Constant.DT_END_DES));

                    sysUserConfigNz.setXcZdJl(String.valueOf(Constant.XC_END_DES));
                    sysUserConfigNz.setSld(String.valueOf(Constant.XC_SLD));

                    sysUserConfigNz.setPcGzCheck(Constant.PC_PERSON_CHECKBOX == true ? "1" : "0");
                    sysUserConfigNz.setPcMinPerson(String.valueOf(Constant.PC_MIN_NUMBER));
                    sysUserConfigNz.setPcMaxPerson(String.valueOf(Constant.PC_MAX_NUMBER));

                    sysUserConfigNz.setDxGzCheck(Constant.DX_PERSON_CHECKBOX == true ? "1" : "0");
                    sysUserConfigNz.setDxMinPerson(String.valueOf(Constant.DX_MIN_NUMBER));
                    sysUserConfigNz.setDxMaxPerson(String.valueOf(Constant.DX_MAX_NUMBER));

                    sysUserConfigNz.setSsGzCheck(Constant.SS_PERSON_CHECKBOX == true ? "1" : "0");
                    sysUserConfigNz.setSsMinPerson(String.valueOf(Constant.SS_MIN_NUMBER));
                    sysUserConfigNz.setsMaxPerson(String.valueOf(Constant.SS_MAX_NUMBER));

                    sysUserConfigNz.setPcCsCheck(Constant.PC_CS_CHECK == true ? "1" : "0");
                    sysUserConfigNz.setPcCsText(Constant.PC_CS_TEXT);

                    sysUserConfigNz.setZdCsCheck(Constant.ZD_CS_CHECK == true ? "1" : "0");
                    sysUserConfigNz.setZdCsText(Constant.ZD_CS_TEXT);

                    sysUserConfigNz.setLxQd(Constant.LX_QD == true ? "1" : "0");
                    sysUserConfigNz.setAccount(Constant.account);

                    boolean b = MyProjectHttpUtil.saveAccountConfig(sysUserConfigNz);

                    if (b){
                        Constant.handler.post(() -> {
                            DialogUtil.showDialog(ContextUtil.context, "保存成功~");
                        });
                    }else {
                        Constant.handler.post(() -> {
                            DialogUtil.showDialog(ContextUtil.context, "保存失败~");
                        });
                    }
                }
            });

        }
    }


    public static void updateStartAddress(String text) {
        startAddressTextVivew.setText(text);
    }

    /**
     * @param text 需要修改的文职
     * @Deprecated 修改启动按钮标题
     */
    public static void updateStartCodeText(String text) {

        if (!Constant.LX_QD) {
            Constant.button.setText(text);
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        Constant.button.setText("保存配置");

    }
}